const utils = require("./utils")
const path = require("path");
const webpack = require("webpack");
const nodeExternals = require("webpack-node-externals");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const { util } = require("webpack");

const baseWebpackConfig = {
  target: "node",
  entry: {
    server: path.join(__dirname, "../src/index.js"),
  },
  resolve: {
    ...utils.getWebpackResolveConfig(),
  },
  output: {
    filename: "[name].bundle.js",
    path: path.join(__dirname, "../dist"),
  },
  module: {
    rules: [
      {
        test: /\/(js|jsx)/,
        use: {
          loader: "babel-loader",
        },
        exclude: [path.join(__dirname, "/node_modules")],
      },
    ],
  },
  externals: [nodeExternals()],
  plugins: [
    new CleanWebpackPlugin(),
    new webpack.DefinePlugin({
      "process.env": {
        NODE_ENV:
          process.env.NODE_ENV === "production" || process.env.NODE_ENV === "prod" ? "'production'" : "'development'",
      },
    }),
  ],
  node: {
    global: true,
    __filename: true,
    __dirname: true,
  },
};

module.exports = baseWebpackConfig;
